define(function(require, exports){
	var util = require('util');
	var pubjs = require('pubjs');
	var grid = require('@base/highGrid');
	var base = require('@base/common/base');
	var $ = require('jquery');

	// 选项卡 -客户端
	var Client = base.tab.extend({
		init: function(config){
			config = pubjs.conf(config, {
				'async': true,	// 异步方式 -用户点击时才加载
				'uuid': util.uuid(),
				'list': {
					'os': {
						text: LANG('操作系统'),
						module: 'subgrid/client.os',
						config: {
							param: config.param,
							hasSearch: false,
							hasFilter: false,
							hasDateRange: true
						}
					},
					'browser': {
						text: LANG('浏览器'),
						module: 'subgrid/client.browser',
						config: {
							param: config.param,
							hasSearch: false,
							hasFilter: false,
							hasDateRange: true
						}
					},
					'language': {
						text: LANG('语言'),
						module: 'subgrid/client.language',
						config: {
							param: config.param,
							hasSearch: false,
							hasFilter: false,
							hasDateRange: true
						}
					},
					'resolution': {
						text: LANG('落地页分辨率'),
						module: 'subgrid/client.resolution',
						config: {
							param: config.param,
							hasSearch: false,
							hasFilter: false,
							hasDateRange: true
						}
					},
					'windowSize': {
						text: LANG('窗口大小'),
						module: 'subgrid/client.windowSize',
						config: {
							param: config.param,
							hasSearch: false,
							hasFilter: false,
							hasDateRange: true
						}
					}
				}
			});
			this.Super('init', arguments);
		}
	});
	exports.base = Client;

	/**	---------------- 报表 (五个)-------------------	**/

	// 操作系统
	var OperatingSystem = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'terminal/os',
					param: {
						order: 'impressions|-1'
					},
					cols: [
						{"type":"id"},
						{name:'os_type_name',text: LANG('操作系统类型'), type:'index', render: 'renderName'}
					],
					// metrics: ["{front}","{back}","{conversion}","{cost}"],
					default_metrics : [
						"impressions","clicks","click_rate","click_reach_rate",
						"back_pageviews",
						"back_regs","back_reg_rate",
						"end_cpc","end_cpm","end_cpa","cost"
					],
					hasSubGrid: false,
					reqType: 'websocket',
					exportParam: 'terminal/os',
					gridName: 'os'
				}
			);

			switch(this.parseSubsCondition(config).pop()){
				case 'spot':
					util.extend(true, config.get(), {
						'tab':{'cost': null}
					});
					break;
			}

			if(util.exist(this.parseSubsCondition(config), 'whisky')){
				util.extend(true, config.get(), {
					'tab':{'cost': null, 'front': null}
				});
			}

			this.Super('init', arguments);
		},
		renderName: function(i, val, data, con){
			var icon = data.os_icon;
			//var name = data.os_type_name;
			var html = [
				'<div>',
					'<img class="fl" src="/resources/images/os/'+(icon||'unkonwn')+'.png" />',
					'<span class="fl ml10">'+val+'</span>',
				'</div>'
			].join('');

			return $(html).width(150);
		}
	});
	exports.os = OperatingSystem;

	// 浏览器
	var Browser = OperatingSystem.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'terminal/browser',
					param: {
						order: 'impressions|-1'
					},
					cols: [
						{"type":"id"},
						{name:'browser_type_name',text: LANG('浏览器名称'), type:'index', render: 'renderName'}
					],
					exportParam: 'terminal/browser',
					gridName: 'bs'
				}
			);
			switch(this.parseSubsCondition(config).pop()){
				case 'spot':
					util.extend(true, config.get(), {
						'tab':{'cost': null}
					});
					break;
			}

			if(util.exist(this.parseSubsCondition(config), 'whisky')){
				util.extend(true, config.get(), {
					'tab':{'cost': null, 'front': null}
				});
			}

			this.Super('init', arguments);
		},
		renderName: function(i, val, data, con){
			var icon = data.browser_icon;
			//var name = data.browser_type_name;
			var html = [
				'<div>',
					'<img class="fl" src="/resources/images/browser/'+(icon||'null')+'.png" />',
					'<span class="fl ml10">'+val+'</span>',
				'</div>'
			].join('');

			return $(html).width(150);
		}
	});
	exports.browser = Browser;

	// 语言
	var Language = OperatingSystem.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'terminal/language',
					param: {
						order: 'impressions|-1'
					},
					cols: [
						{"type":"id"},
						{name:'language_name',text: LANG('语言'), type:'index', render: 'renderName'}
					],
					exportParam: 'terminal/language',
					gridName: 'language'
				}
			);

			switch(this.parseSubsCondition(config).pop()){
				case 'spot':
					util.extend(true, config.get(), {
						'tab':{'cost': null}
					});
					break;
			}

			if(util.exist(this.parseSubsCondition(config), 'whisky')){
				util.extend(true, config.get(), {
					'tab':{'cost': null, 'front': null}
				});
			}

			this.Super('init', arguments);
		},
		renderName: function(i, val, data, con){
			return val;
		}
	});
	exports.language = Language;

	// 落地页分辨率
	var Resolution = grid.base.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'terminal/resolution',
					cols: [
						{"type":"id"},
						{name:'resolution_name',text: LANG('落地页分辨率'), type:'index'}
					],
					// metrics: ["{back}","{conversion}"],
					tab: {'back': true, 'conversion': true},
					default_metrics : [
						"back_pageviews","back_click","back_click_rate","back_avg_staytime","back_avg_loadtime","back_avg_pagepixels",
						"back_regs","back_reg_rate","back_logins","back_login_rate"
					],
					reqType: 'websocket',
					exportParam: 'terminal/resolution',
					gridName: 'resolution'
				}
			);
			this.Super('init', arguments);
		}
	});
	exports.resolution = Resolution;

	// 窗口大小
	var WindowSize = Resolution.extend({
		init: function(config){
			config = pubjs.conf(config, {
					url: 'terminal/pixel',
					cols: [
						{"type":"id"},
						{name:'pixels_name',text: LANG('窗口大小'), type:'index'}
					],
					exportParam: 'terminal/pixel',
					gridName: 'windowSize'
				}
			);
			this.Super('init', arguments);
		}
	});
	exports.windowSize = WindowSize;

});